import evaluate
import requests
# 测试镜像网站连接
try:
    response = requests.get("https://hf-mirror.com", timeout=10)
    print(f"镜像网站连接成功，状态码: {response.status_code}")
except Exception as e:
    print(f"镜像网站连接失败: {e}")


# 联网时预先下载模块
def download_metrics():

	metrics_to_download = ["accuracy", "f1", "precision", "recall"]

	for metric_name in metrics_to_download:
		try:
			print(f"正在下载 {metric_name}...")
			metric = evaluate.load(metric_name, download_mode = "force_redownload")
			print(f"成功下载 {metric_name}")
		except Exception as e:
			print(f"下载 {metric_name} 失败: {e}")
download_metrics()

all_modules = evaluate.list_evaluation_modules()
accuracy_modules = [m for m in all_modules if 'accuracy' in m.lower()]
print(f"包含accuracy的评估模块有：{accuracy_modules}")
#加载模块
accuracy = evaluate.load("lvwerra/accuracy_score", download_mode = "force_redownload")
print(accuracy)





